package com.zac.coroutine.algorithm.selectionsort

/**
 * author zac
 * date 2024/10/11
 *
 */
class InsertSort {


    companion object {
        @JvmStatic
        fun main(args: Array<String>) {

            insertSort(arrayOf(4, 1, 5, 2, 6, 9, 7, 8))
        }

        fun insertSort(arr: Array<Int>) {
            for (i in 0 until arr.size - 1) {
                var j = i
                while (j >= 0 && arr[j] > arr[j + 1]) {
                    val temp = arr[j]
                    arr[j] = arr[j + 1]
                    arr[j + 1] = temp
                    j--
                }

            }
            arr.print()


        }


    }


}
